package com.cby.operation.initialize.data

import com.cby.operation.sdk.CODE_GAME_MAINTENANCE
import com.cby.operation.sdk.CODE_SUCCESS
import org.json.JSONObject

/**
 * Description:快爆SDK初始化的相关配置数据
 *
 * @author 陈宝阳
 * @create 2020/8/10 10:23
 */
internal class InitConfig {
    /** 游戏名  */
    var gameName: String? = null
        private set

    /** 游戏图标  */
    var gameIcon: String? = null
        private set

    /** 维护开始时间  */
    var startTime: String? = null
        private set

    /** 维护结束时间  */
    var endTime: String? = null
        private set

    /** 维护的公告  */
    var maintainContent: String? = null
        private set
    var validity = 0
        private set

    companion object {

        /** 正常的游戏数据  */
        private const val KEY_RESPONSE_GAME_NAME = "gameName"
        private const val KEY_RESPONSE_GAME_ICON = "gameIcon"

        /** 维护  */
        private const val KEY_RESPONSE_START_TIME = "maintenanceStartTime"
        private const val KEY_RESPONSE_END_TIME = "maintenanceEndTime"
        private const val KEY_RESPONSE_CONTENT = "maintenanceContent"
        private const val KEY_RESPONSE_VALIDITY = "validity"

        /**
         * json解析
         * @param dataJson
         * @param code
         * @return
         */
        fun parseJson(dataJson: JSONObject, code: Int): InitConfig {
            val config = InitConfig()
            if (code == CODE_SUCCESS) {
                config.gameName = dataJson.optString(KEY_RESPONSE_GAME_NAME)
                config.gameIcon = dataJson.optString(KEY_RESPONSE_GAME_ICON)
                config.validity = dataJson.optInt(KEY_RESPONSE_VALIDITY)
            } else if (code == CODE_GAME_MAINTENANCE) {
                config.startTime = dataJson.optString(KEY_RESPONSE_START_TIME)
                config.endTime = dataJson.optString(KEY_RESPONSE_END_TIME)
                config.maintainContent = dataJson.optString(KEY_RESPONSE_CONTENT)
            }
            return config
        }
    }
}